const {
  $util,
} = getApp();
Page({
  data: {
    page: 1,
    list: [],
    hasMore: true,
    loaded: false,
    imgUrl: $util.getImgUrl(),
  },
  onLoad(opts) {
    wx.setNavigationBarTitle({
      title: opts.barTitle && decodeURIComponent(opts.barTitle) || '谈心谈话',
    });
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
  },
  loadList() {
    const D = this.data;
    $util.request({
      url: 'entry/wxapp/partylife.talk.predicttalk',
      data: {
        page: D.page,
      },
      success: (res) => {
        let list = res.data;
        if (D.page > 1) {
          list = [...D.list, ...list];
        }
        this.setData({
          list,
          hasMore: parseInt(res.total, 0) > list.length,
          page: parseInt(res.total, 0) > list.length ? D.page + 1 : D.page,
          loaded: true,
        });
      },
    });
  },
  loadMore() {
    this.data.hasMore && this.loadList();
  },
  torecord() {
    wx.navigateTo({
      url: '/ws_party_const/pages/txth-record/txth-record',
    });
  },
});